package com.zhou.test.spring.secrity.operatorlog;


import com.zhou.common.operator.log.core.model.PrincipalInfo;
import com.zhou.common.operator.log.core.resolver.AbstractHttpServletRequestPrincipalResolver;
import com.zhou.test.spring.secrity.content.UserContext;
import com.zhou.test.spring.secrity.model.security.MyUserDetails;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class PrincipalResolver extends AbstractHttpServletRequestPrincipalResolver {

    @Override
    protected PrincipalInfo resolveWithRequest(HttpServletRequest request) {
        MyUserDetails userDetails = UserContext.currentUser();

        PrincipalInfo principalInfo = new PrincipalInfo();
        principalInfo.setUserId(userDetails.getUserId() + "");
        principalInfo.setUserName(userDetails.getUsername());
        principalInfo.setUserPhone(userDetails.getPhone());
        principalInfo.setOrgId(userDetails.getCurrOrgId() + "");
        principalInfo.setOrgName(userDetails.getCurrOrgName() + "");
        return principalInfo;
    }


}